<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增师生风采信息')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-style-add">
            <div class="form-group">
                <label class="col-sm-3 control-label">标题：</label>
                <div class="col-sm-8">
                    <input name="title" class="form-control" type="text">                   
                </div>
            </div>
            <div class="form-group">                
                <label class="col-sm-3 control-label" for="coursePicture">风采的图片：</label>
                <input name="picture" id="picture" class="form-control" type="hidden">
                <div class="col-sm-8">                    
                    <input type="file" class="" name="coursePicture" id="coursePicture" accept="image/*"/>
                    <img src="" alt="" id="yl" width="20px" height="20px" display="none"/>
                    <button class="btn" type="button" id="upload">上传</button>
                </div>
            </div> 
            <div class="form-group">                
                <label class="col-sm-3 control-label" for="coursePicture">风采的视频：</label>
                <input name="video" id="video" class="form-control" type="hidden">
                <div class="col-sm-8">                    
                    <input type="file" class="" name="courseVideo" id="courseVideo" accept="video/*"/>                    
                    <button class="btn" type="button" id="upload2">上传</button>
                </div>
            </div> 
            <div class="form-group">    
                <label class="col-sm-3 control-label">说明：</label>
                <div class="col-sm-8">
                    <textarea name="introduce" class="form-control"></textarea>                   
                </div>
            </div>
            <!--
            <div class="form-group">    
                <label class="col-sm-3 control-label">状态：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('wct_teacher_style')}">
                        <input type="radio" th:id="${'status_' + dict.dictCode}" name="status" th:value="${dict.dictValue}" th:checked="${dict.default}">
                        <label th:for="${'status_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
             <div class="form-group">    
                <label class="col-sm-3 control-label">创建人：</label>
                <div class="col-sm-8">
                    <input name="createUser" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">修改人：</label>
                <div class="col-sm-8">
                    <input name="updateUser" class="form-control" type="text">
                </div>
            </div> -->
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script type="text/javascript">
        var prefix = ctx + "course/style"
        $("#form-style-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-style-add').serialize());
            }
        }
        
        //上传课程图片......
        $('#coursePicture').on('change', function() {
            var reader = new FileReader();
            reader.onload = function(e) {
                var src = e.target.result;
                //根据MIME判断上传的文件是不是图片类型
                if((src).indexOf("image/")==-1){
                    $.modal.alertWarning("文件格式错误，请上传图片类型,如：JPG，PNG后缀的文件。");                    
                } else {
                    $("#yl").attr("src",src);
                }
            }
            reader.readAsDataURL(this.files[0]);
        })
        
       //确定图片上传的话......
       $("#upload").click(function(){
    	   //判断文件是否为空
    	   var file=$("#coursePicture")[0];
    	   if(file.value==null || file.value==''){
    		   $.modal.alertWarning("请先选择上传的图片,图片类型,如：JPG，PNG后缀的文件。");   
    		   return;    		   
    	   }    	   
    	   var formdata = new FormData();
    	   formdata.append("coursePicture",file.files[0]);
    	   $.ajax({
    	        url: prefix + "/uploadImg",
    	        data: formdata,
    	        type: "post",
    	        processData: false,
    	        contentType: false,
    	        success: function(result) {    	        	
    	        	if(result.code=='0'){    
    	        		$.modal.alertWarning("上传图片成功......");
    	        		$("#picture").val(result.msg);    	        		
    	        	}else{    	        		
    	        		$.modal.alertWarning("上传图片失败！请重新上传图片,图片类型如：JPG，PNG后缀的文件。");
    	        	}    	        	
    	        }
    	    })   	   
       });       
      
        //确定图片上传的话......
        $("#upload2").click(function(){
     	   //判断文件是否为空
     	   var file=$("#courseVideo")[0];
     	   if(file.value==null || file.value==''){
     		   $.modal.alertWarning("请先选择上传的视频,视频类型如：mp4,avi等类型的文件。");   
     		   return;    		   
     	   }    	   
     	   var formdata = new FormData();
     	   formdata.append("courseVideo",file.files[0]);
     	   $.ajax({
     	        url: prefix + "/uploadVideo",
     	        data: formdata,
     	        type: "post",
     	        processData: false,
     	        contentType: false,
     	        success: function(result) {    	        	
     	        	if(result.code=='0'){    
     	        		$.modal.alertWarning("上传视频成功......");
     	        		$("#video").val(result.msg);    	        		
     	        	}else{    	        		
     	        		$.modal.alertWarning("上传视频失败！请重新上传视频,视频类型如：mp4,avi等类型的文件。");
     	        	}    	        	
     	        }
     	    })   	   
        });       
                
        
    </script>
</body>
</html>